package sng.modules.view.components.city.logic.unit
{
	import core.interfaces.IDispose;
	
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	
	import sng.data.info.GlobalInfo;
	import sng.modules.view.components.city.logic.CityView;
	import sng.utils.AttachmentTextUpUtil;
	import sng.utils.FilterUtil;
	import sng.utils.IconUtil;

	public class DropAttachment extends Tile implements IDispose
	{
		private var view:CityView;
		public var attachment:MovieClip;
		private var type:String;
		//记录数值 eaosn 20110719
		private var building:BaseBuilding;
		
		public function DropAttachment(_view:CityView, _type:String, _building:BaseBuilding, _callbackFuncArray:Array=null)
		{
			view = _view;
			type = _type;
			building=_building;
			switch(type)
			{
				case "coin":
					attachment = new AttachmentCoin();
					break;
				case "goods":
					attachment = new AttachmentGoods();
					break;
				case "exp":
					attachment = new AttachmentExp();
					break;
			}
			//鼠标悬浮发光 eason 20110718
			attachment.addEventListener(MouseEvent.MOUSE_OVER,onMouseOver);
			attachment.addEventListener(MouseEvent.MOUSE_OUT,ouMouseOut);
			
			this.sprites.push(attachment);
			invalidateSprites();
			attachment.scaleX = attachment.scaleY = (1/_view.currentZoom);
			
			attachment.addEventListener(MouseEvent.CLICK, gatherOver);
			attachment.addEventListener("gatherOver", gatherOver);
		}
		
		//鼠标悬浮发光 eason 20110718
		private function onMouseOver(evt:MouseEvent):void
		{
			attachment.filters=[FilterUtil.getHighLigitFilter()];
		}
		
		//鼠标悬浮发光 eason 20110718
		private function ouMouseOut(evt:MouseEvent):void
		{
			attachment.filters=[];
		}
		
		protected function gatherOver(event:Event=null):void
		{
			attachment.removeEventListener(MouseEvent.MOUSE_OVER,onMouseOver);
			attachment.removeEventListener(MouseEvent.MOUSE_OUT,ouMouseOut);
			
			attachment.removeEventListener(MouseEvent.CLICK, gatherOver);
			attachment.removeEventListener("gatherOver", gatherOver);
			
			var bPoint:Point = new Point(0, 0);
			bPoint = attachment.localToGlobal(bPoint);
			trace(bPoint.x,bPoint.y);
			//添加相应vo的值 eason 20110719
			switch(type)
			{
				case "coin":
					//更改数值
					IconUtil.changeValue(GlobalInfo.mainvo,"money",building.vo.dropCoin*(1+building.uVO.totalBonusRate));
					
					//显示增加的数字
					AttachmentTextUpUtil.addText(building,"+"+building.vo.dropCoin*(1+building.uVO.totalBonusRate)+"金币",AttachmentTextUp.YELLOW,-60);
					break;
				case "exp":
					//更改数值
					GlobalInfo.mainvo.experience+=building.vo.dropExp*(1+building.uVO.totalBonusRate);
					//显示增加的数字
					AttachmentTextUpUtil.addText(building,"+"+building.vo.dropExp*(1+building.uVO.totalBonusRate)+"经验",AttachmentTextUp.GREEN,+20);
					break;
				case "goods":
					//更改数值
					GlobalInfo.mainvo.goods+=building.vo.dropGoods*(1+building.uVO.totalBonusRate);
					//显示增加的数字
					AttachmentTextUpUtil.addText(building,"+"+building.vo.dropGoods*(1+building.uVO.totalBonusRate)+"货物",AttachmentTextUp.WHITE,-100);
					break;
			}
			

			view.city.doGatherAnimation(bPoint, type);
			
			
			//如果是自己拾取的,做连续拾取动画效果
			if(event.type=="click")
			{
				view.city.bonus.AddBonus();
			}
			dispose();
		}
		
		override public function dispose():void
		{
			attachment = null;
			view.attachmentScene.removeDrop(this);
		}
	}
}